import time
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get('https://www.baidu.com')
driver.maximize_window()
time.sleep(2)
print(driver.current_window_handle)
driver.find_element(By.PARTIAL_LINK_TEXT,'新').click()
time.sleep(1)
print(driver.window_handles)
news = driver.window_handles
driver.switch_to.window(news[1])
time.sleep(1)
print(driver.current_window_handle)
driver.close()
time.sleep(2)
driver.switch_to.window(news[0])
print(driver.current_window_handle)